package com.cloud.pole.weixin.util.wxpay;

import java.io.FileInputStream;
import java.io.InputStream;
import org.springframework.util.ResourceUtils;

import com.cloud.pole.weixin.util.wxpay.sdk.IWXPayDomain;
import com.cloud.pole.weixin.util.wxpay.sdk.WXPayConfig;

public class WxConfig extends WXPayConfig {
	private static WxConfig wxAppRyConfig;
	private static String appID;
	private static String mchID;
	private static String key;
	private static IWXPayDomain iWXPayDomain;
	private String realPath;
	static {
		iWXPayDomain = new WxRyDomain("api.mch.weixin.qq.com", true);
	}
	public WxConfig(){
		
	}
	
	public WxConfig(String appid){
		appID = appid;
	}
	
	public WxConfig(String appid,String mchid,String wxkey){
		appID = appid;
		mchID = mchid;
		key = wxkey;
		
	}
	public static WxConfig getInstance() {
		if (wxAppRyConfig == null) {
			wxAppRyConfig = new WxConfig();
		}
		return wxAppRyConfig;
	}

	@Override
	public String getAppID() {
		return appID;
	}

	@Override
	public String getMchID() {
		return mchID;
	}

	@Override
	public String getKey() {
		return key;
	}

	@Override
	public InputStream getCertStream() {
		try {
			// realPath = ResourceUtils.getFile("classpath:test.txt");
			// System.out.println("realPath:" + realPath);
			// InputStream certInputStream = new FileInputStream(new
			// File(realPath+ "apiclient_cert.p12"));
			String certfilename = "classpath:" + mchID + "_apiclient_cert.p12";
			InputStream certInputStream = new FileInputStream(ResourceUtils.getFile(certfilename));
			return certInputStream;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;

	}

	@Override
	public IWXPayDomain getWXPayDomain() {
		return iWXPayDomain;
	}

}
